import { getListApi } from "@/api/configCenter/warehouseCode";
import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";
import { getListApi as getAllCountryApi } from "@/api/configCenter/countryRegion";
import { reactive } from "vue";
import { getAllCompanyApi, getUserByPositionApi } from "@/api/managementCenter/departmentPersonnel";
import { getListApi as warehosueManagementApi } from "@/api/managementCenter/warehosueManagement";
import { getListApi as outWarehouseBrokerIdsApi } from "@/api/configCenter/outBoundAgent/index";
import { getTreeChannelApi } from "@/api/configCenter/warehouseEntryChannel";
import { TreeSelect } from "ant-design-vue";
const SHOW_CHILD = TreeSelect.SHOW_CHILD;
export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "关键字",
    keyName: "keyWordsList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "仓库代码",
    keyName: "warehouseCodeList",
    optionsRequest: getListApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "warehouseCode",
      value: "warehouseCode"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "input",
    label: "邮编",
    keyName: "zipCode"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "跟单员",
    keyName: "followIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "5", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "dict-select",
    label: "标识",
    keyName: "markList",
    lookupCode: "LOGOTYPE",
    optConfig: {
      label: "name",
      value: "code"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  },
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNumList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  {
    type: "select",
    label: "制作发票",
    keyName: "makeInvoiceStatus",
    optConfig: {
      label: "name",
      value: "code"
    },
    options: [
      {
        name: "未制作",
        code: -1
      },
      {
        name: "已制作",
        code: -2
      }
    ]
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "目的地",
    keyName: "countryRegionIdList",
    optionsRequest: getAllCountryApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "region",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "dict-select",
    label: "未标识",
    keyName: "notMark",
    lookupCode: "LOGOTYPE",
    optConfig: {
      label: "name",
      value: "code"
    },
    options: []
  },
  {
    type: "dict-select",
    label: "交税方式",
    keyName: "customsTaxesTypeList",
    lookupCode: "TAX_PAYMENT_METHOD",
    optConfig: {
      label: "name",
      value: "code"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "经营单位",
    keyName: "companyIds",
    optionsRequest: getAllCompanyApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "input",
    label: "转单号",
    keyName: "transferOrderNumberList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  {
    type: "dict-select",
    label: "报关方式",
    keyName: "customsDeclarationType",
    lookupCode: "CUSTOMS_DECLARATION_METHOD",
    optConfig: {
      label: "name",
      value: "code"
    },
    options: []
  },
  {
    type: "input",
    label: "客户备注",
    keyName: "remark"
  },
  {
    type: "dict-select",
    label: "仓库属性",
    keyName: "warehousePropertyList",
    lookupCode: "WAREHOUSE_PROPERT",
    optConfig: {
      label: "name",
      value: "name"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  },
  {
    type: "datetimerange",
    label: "下单时间",
    keyName: "createdTime"
  },
  {
    type: "datetimerange",
    label: "拣货时间",
    keyName: "depositTime"
  },
  {
    type: "input",
    label: "FBA单号",
    keyName: "fbaNumberList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "渠道",
    keyName: "channelIdList",
    optionsRequest: getTreeChannelApi,
    optReqParams: {},
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "label",
      value: "value",
      children: "children"
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  {
    type: "input",
    label: "内部备注",
    keyName: "innerRemark"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "出仓代理",
    keyName: "outWarehouseBrokerIds",
    optionsRequest: outWarehouseBrokerIdsApi,
    optReqParams: { pageNum: 1, pageSize: 999, beforePageNum: 0, name: "", total: 0, status: undefined },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    options: []
  }),
  {
    type: "datetimerange",
    label: "出仓时间",
    keyName: "outWarehouseTime"
  },

  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "拣货仓库",
    keyName: "warehouseNames",
    optionsRequest: warehosueManagementApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "cnName",
      value: "cnName"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "4", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  })
];

export const tableColumn: Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem> = [
  {
    type: "checkbox",
    field: "checkbox",
    minWidth: "50"
  },
  {
    field: "customerName",
    title: "客户简称",
    minWidth: "120",
    sortable: true
  },
  {
    field: "fbaNumber",
    title: "FBA单号",
    minWidth: "140"
  },
  {
    field: "waybillNum",
    title: "运单号",
    minWidth: "180",
    renderSlot: "waybillNum"
  },
  {
    field: "pushOrderTag",
    title: "推单状态",
    minWidth: "150"
  },
  {
    field: "warehouseName",
    title: "拣货仓库",
    minWidth: "90",
    sortable: true
  },
  {
    field: "mergeNo",
    title: "合并报关号",
    minWidth: "90"
  },
  {
    field: "splitFoamRatio",
    title: "泡比",
    minWidth: "90"
  },
  {
    field: "countryRegionName",
    title: "目的地",
    minWidth: "90",
    sortable: true
  },
  {
    field: "mark",
    title: "标识",
    minWidth: "80"
  },
  {
    field: "transferOrderNumber",
    title: "转单号",
    minWidth: "130"
  },
  {
    field: "tracksStatus",
    title: "最新轨迹",
    minWidth: "160"
  },
  {
    field: "locusUpdateTime",
    title: "轨迹更新时间",
    minWidth: "135",
    formatter: "formatDate",
    sortable: true
  },
  {
    field: "companyName",
    title: "经营单位",
    minWidth: "90",
    sortable: true
  },
  {
    field: "warehouseCode",
    title: "仓库代码",
    minWidth: "100"
  },
  {
    field: "receivableFeePrice",
    title: "应收费用",
    minWidth: "90"
  },
  {
    field: "warehouseProperty",
    title: "仓库属性",
    minWidth: "120",
    sortable: true
  },
  {
    field: "channelName",
    title: "渠道",
    minWidth: "140",
    sortable: true
  },
  {
    field: "itemNumber",
    title: "件数",
    minWidth: "80"
  },
  {
    field: "settlementWeight",
    title: "结算重",
    minWidth: "80"
  },
  {
    field: "actualWeight",
    title: "实重",
    minWidth: "80"
  },
  {
    field: "volumeWeight",
    title: "材积重",
    minWidth: "80"
  },
  {
    field: "squaresNumber",
    title: "方数",
    minWidth: "80"
  },
  {
    field: "zipCode",
    title: "邮编",
    minWidth: "90"
  },
  {
    field: "productName",
    title: "品名",
    minWidth: "120"
  },
  {
    field: "materialQualityName",
    title: "材质",
    minWidth: "120"
  },
  {
    field: "remark",
    title: "客户备注",
    minWidth: "120"
  },
  {
    field: "innerRemark",
    title: "内部备注",
    minWidth: "120"
  },
  {
    field: "makeInvoiceStatus",
    title: "制作发票",
    minWidth: "120",
    renderSlot: "makeInvoiceStatus",
    sortable: true
  },
  {
    field: "depositTime",
    title: "拣货时间",
    minWidth: "135",
    formatter: "formatDate",
    sortable: true
  },
  {
    field: "bizName",
    title: "业务员",
    minWidth: "90",
    sortable: true
  },
  {
    field: "followName",
    title: "跟单员",
    minWidth: "90",
    sortable: true
  },
  {
    field: "addressType",
    title: "运单类型",
    minWidth: "120",
    renderSlot: "addressType",
    sortable: true
  },
  {
    field: "status",
    title: "运单状态",
    minWidth: "120",
    renderSlot: "status",
    fixed: "right"
  },
  {
    field: "action",
    title: "操作",
    minWidth: "90",
    renderSlot: "action",
    fixed: "right"
  }
];
// 统计
export const statisticsColumn: Array<{ field: string; label: string }> = [
  {
    label: "票数",
    field: "shipmentCount"
  },
  {
    label: "件数",
    field: "itemNumberSum"
  },

  {
    label: "方数",
    field: "squaresNumberSum"
  },
  {
    label: "实重",
    field: "actualWeightSum"
  },
  {
    label: "材积重",
    field: "volumeWeightSum"
  },
  {
    label: "结算重",
    field: "settlementWeightSum"
  },
  {
    label: "应收金额",
    field: "receiveAmountSum"
  }
];
